package time

import (
	"time"
)

//执行时间计时器
type TimeState struct {
	statTime time.Time //下载开始时间
	endTime  time.Time //下载结束时间
}

//开始计时
func StartTimeState() *TimeState {
	state := &TimeState{}
	state.Start()
	return state
}

//开始计时
func (down *TimeState) Start() time.Time {
	down.statTime = time.Now()
	return down.statTime
}

//终止计时
func (down *TimeState) End() time.Time {
	down.endTime = time.Now()
	return down.endTime
}

//获取执行时间
func (down *TimeState) GetExeTime() time.Duration {
	if (down.endTime == time.Time{}) {
		return time.Now().Sub(down.statTime)
	}
	return down.endTime.Sub(down.statTime)
}
